package kr.ac.konkuk.dblab.point.quadtree;

import java.awt.geom.Point2D;
import java.util.HashSet;
import java.util.Set;


public abstract class AbstractCompositeNode extends AbstractNode implements CompositeNode {
	private Node []children = new Node[CompositeNode.CHILD_COUNT];
	private int count = 0;
	
	public AbstractCompositeNode(NodeType type) {
		super(type, false, 0);
	}
	
	public Node child(int i) {
		return children[i];
	}
	
	public void attach(Node node) {
		children[node.type().index()] = node;
		node.parent(this);
		
		++count;
	}
	
	public Set<Point2D> points() {
		Set<Point2D> points = new HashSet<Point2D>();
		for (Node node : children) {
			points.addAll(node.points());
		}
		
		return points;
	}
}
